package com.cskaoyan.gateway.controller.user;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.commons.tool.utils.CookieUtil;
import com.mall.user.annotation.Anoymous;
import com.mall.user.intercepter.TokenIntercepter;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @ClassName: LoginOutController
 * @Author: 南风
 * @Email: 1480207032@qq.com
 * @Description:
 * @Date: 2020/7/11 20:44
 */
@RestController
@RequestMapping("user")
@Anoymous
public class LogoutController {

    @GetMapping("loginOut")
    public ResponseData logout(HttpServletRequest request, HttpServletResponse response){
        Cookie[] cookies = request.getCookies();
        for (Cookie cookie : cookies) {
            /*if (cookie.getName().equals("access_token")){
                continue;
            }*/
            cookie = CookieUtil.genCookie(cookie.getName(), cookie.getValue(), "/",
                    0);
            cookie.setHttpOnly(true);
            CookieUtil.setCookie(response, cookie);
        }

        return new ResponseUtil<>().setData(null);

        /*UserLogoutRequest userLogoutRequest = new UserLogoutRequest();

        UserLogoutResponse userLogoutResponse = logoutService.logout(userLogoutRequest);
        if (userLogoutResponse.getCode().equals(SysRetCodeConstants.SUCCESS.getCode())){
            return new ResponseUtil<>().setData(null);
        }
        return new ResponseUtil<>().setErrorMsg(userLogoutResponse.getMsg());*/
    }
}
